﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using RightClickExtension.Properties;
using System.IO;

namespace RightClickExtension
{
    public partial class frmConfig : Form
    {
        #region .ctors

        public frmConfig()
        {
            InitializeComponent();
            tbPath.Text = Settings.Default.TargetPath;
        }

        #endregion

        #region Auxiliary methods

        private void btnChange_Click(object sender, EventArgs e)
        {
            DialogResult dr = folderDialog.ShowDialog();
            if (dr == DialogResult.OK)
            {
                if (folderDialog.SelectedPath != tbPath.Text)
                {
                    btnSave.Enabled = true;
                    tbPath.Text = folderDialog.SelectedPath;
                }

            }
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                Settings.Default.TargetPath = folderDialog.SelectedPath;
                Settings.Default.Save();
                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error save new start folder");
                Helper.WriteToErrorLog(ex, "BtnSave new path");
            }
        }

        private void lblLog_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            string logLocation = Path.Combine(Application.StartupPath, "log.txt");
            if (File.Exists(logLocation))
                System.Diagnostics.Process.Start("notepad.exe", logLocation);
        }

        private void lblErrorLog_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            string logLocation = Path.Combine(Application.StartupPath, "Errorlog.txt");
            if (File.Exists(logLocation))
                System.Diagnostics.Process.Start("notepad.exe", logLocation);
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        #endregion
    }
}
